var stopTime = null;

function SunshineOnload() {
    $('#sunshine_sunlight_strat').click(function() {
        setvisible('play')
    })
    $('#sunshine_sunlight_end').click(function() {
        setvisible('stop')
    })
    $('#sunshine_clear').click(function() {
        setvisible('clear')
    })
}

function stopPlay() {
    stopTime = viewer.clock.currentTime,
        viewer.clock.shouldAnimate = !1
}

function clearPlay() {
    viewer.scene.globe.enableLighting = false;
    viewer.shadows = false;
}

function stratPlay() {
    var sunshine_selDate = $('#sunshine_selDate').val();
    var sunshine_startTime = $('#sunshine_startTime').val();
    var sunshine_endTime = $('#sunshine_endTime').val();
    if (sunshine_startTime > sunshine_endTime) {
        return;
    }
    if (viewer.clock.shouldAnimate = !0, stopTime) {
        viewer.scene.globe.enableLighting = true;
        viewer.shadows = true;
        viewer.clock.currentTime = stopTime;
    } else {

        var e = sunshine_selDate,
            t = new Date(e),
            i = sunshine_startTime,
            a = sunshine_endTime,
            r = new Date(new Date(t).setHours(Number(i))),
            o = new Date(new Date(t).setHours(Number(a)));
        viewer.scene.globe.enableLighting = !0,
            viewer.shadows = !0,
            viewer.clock.startTime = Cesium.JulianDate.fromDate(r),
            viewer.clock.currentTime = Cesium.JulianDate.fromDate(r),
            viewer.clock.stopTime = Cesium.JulianDate.fromDate(o),
            viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP,
            viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK_MULTIPLIER,
            viewer.clock.multiplier = 1600
    }
}

function setvisible(value) {
    switch (value) {
        case 'play':
            stratPlay();
            break;
        case 'stop':
            stopPlay();
            break;
        case 'clear':
            clearPlay();
            break;
    }
}